package com.example.demo.service.system;

import com.example.demo.dao.system.PermissionDAO;
import com.example.demo.model.system.Permission;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PermissionService {
    @Autowired
    private PermissionDAO dao;

    public List<Permission> selectBySuperId(Integer super_id) {
        return dao.selectBySuperId(super_id);
    }

    public List<Permission> selectAll() {
        return dao.selectAll();
    }

    public Integer addPermission(Permission permission) {
        return dao.addPermission(permission);
    }

    public Integer deleteById(Integer permission_id) {
        return dao.deleteById(permission_id);
    }

    public Integer updateById(Permission permission) {
        return dao.updateById(permission);
    }

    public List<Permission> findPermission(String title, String url, Integer super_id) {
        return dao.findPermission(title, url, super_id);
    }

    public Boolean save(Permission permission) {
        Boolean flag = false;

        if (permission.getPermission_id() != null) {
            flag = dao.updateById(permission) == 1;
        } else {
            flag = dao.addPermission(permission) == 1;
        }

        return flag;
    }
}
